<% groups = @site.get_field_groups %>
<!-- PAGE CONTENT WRAPPER -->
<div class="page-content-wrap">
  <div class="panel panel-default">
    <div class="panel-heading">
      <h4><span class="fa fa-cog"></span> <%= "#{t('camaleon_cms.admin.settings.configuration_site')}: #{@site.the_title} " %> </h4>
    </div>
    <%= form_for @site, as: "site", url: {action: :site_saved}, html: {id: "site_settings_form", class: "panel-body cama_ajax_request validate"} do |f| %>
        <div class="tabs">
          <ul role="tablist" class="nav nav-tabs">
            <li class="<%= "active" if ["", nil].include?(params[:tab]) %>">
              <a data-toggle="tab" role="tab" href="#tab-information" aria-expanded="false"><%= t('camaleon_cms.admin.settings.information_basic') %></a>
            </li>
            <li class="<%= "active" if "config" == params[:tab] %>">
              <a data-toggle="tab" role="tab" href="#tab-configuration" aria-expanded="false"><%= t('camaleon_cms.admin.post_type.configuration') %></a>
            </li>
            <% if groups.present? %>
                <li class="<%= "active" if "other_config" == params[:tab] %>">
                  <a data-toggle="tab" role="tab" href="#tab-other-configuration" aria-expanded="false"><%= t('camaleon_cms.admin.post_type.other_configuration') %></a>
                </li>
            <% end %>
            <li class="<%= "active" if "seo" == params[:tab] %>">
              <a data-toggle="tab" role="tab" href="#tab-seo_settings" aria-expanded="false"><%= t('camaleon_cms.admin.settings.seo_setting') %></a>
            </li>
            <li class="<%= "active" if "email" == params[:tab] %>"><a data-toggle="tab" role="tab" href="#tab-email_settings" aria-expanded="false"><%= t('camaleon_cms.admin.settings.email_settings') %></a></li>
            <li class="<%= 'active' if 'filesystem' == params[:tab] %>"><a data-toggle="tab" role="tab" href="#tab-filesystem_settings" aria-expanded="false"><%= t('camaleon_cms.admin.settings.filesystem_settings', default: 'Filesystem Settings ') %></a></li>
            <li class="<%= 'active' if 'media' == params[:tab] %>"><a data-toggle="tab" role="tab" href="#tab-media_settings" aria-expanded="false"><%= t('camaleon_cms.admin.settings.media_settings', default: 'Media Settings') %></a></li>
          </ul>
          <div class="panel-body tab-content row">

            <%= render partial: 'layouts/camaleon_cms/admin/form_error', locals: {data: @site} %>

            <div id="tab-information" class="tab-pane <%= "active" if ["", nil].include?(params[:tab]) %> ">
              <div class="form-group">
                <%= f.label t('camaleon_cms.admin.button.domain', default: 'Domain') %><br>
                <small><%= t('camaleon_cms.admin.sites.message.enter_key_domain', default: 'Enter your domain here') %></small>
                <br>
                <%= f.text_field :slug, :class => "form-control required" %>
              </div>
              <div class="form-group">
                <%= f.label t('camaleon_cms.admin.table.name') %><br>
                <%= f.text_field :name, :class => "form-control translatable" %>
              </div>
              <div class="form-group">
                <%= f.label t('camaleon_cms.admin.table.description') %><br>
                <%= f.text_area :description, :class => "form-control translatable" %>
              </div>
              <div class="form-group admin_logo_upload">
                <label for=""><%= t('camaleon_cms.admin.table.logo') %></label><br>
                <%= hidden_field :options, :logo, :class => "form-control unput_upload", :value => @site.get_option("logo"), "data-label" => "#{t('camaleon_cms.admin.button.upload_image')}" %>
              </div>
              <div class="form-group admin_icon_upload">
                <label for=""><%= t('camaleon_cms.admin.table.favicon') %></label><br>
                <%= hidden_field :options, :icon, :class => "form-control unput_upload", :value => @site.get_option("icon"), "data-label" => "#{t('camaleon_cms.admin.button.upload_icon')}", "data-ext" => "ico" %>
              </div>
            </div>
            <%= render "configuration_settings", f: f %>
            <% if groups.present? %>
                <div id="tab-other-configuration" class="<%= "active" if "other_config" == params[:tab] %> tab-pane ">
                  <%= render partial: "camaleon_cms/admin/settings/custom_fields/render", locals: {record: @site, field_groups: groups} %>
                </div>
            <% end %>
              <%= render "seo_settings", f: f %>
              <%= render "email_settings", f: f %>
              <%= render "file_system_settings", f: f %>
              <%= render "media_settings", f: f %>
          </div>
          <div class="panel-footer">
            <button class="btn btn-primary pull-right" type="submit"><%= t('camaleon_cms.admin.button.submit') %></button>
          </div>
        </div>
    <% end %>
  </div>
</div>
<script>
    jQuery(function () {
        var panel = $("#site_settings_form");
        panel.validate();
        panel.find('.unput_upload, .input_upload').input_upload();

        // smtp
        panel.find("#options_mailer_enabled").change(function () {
            if (!$(this).is(":checked"))
                panel.find("#tab-email_settings .toggleable").find("input, select, textarea").not(this).not("input[type='hidden']").attr("disabled", true)
            else
                panel.find("#tab-email_settings .toggleable").find("input, select, textarea").not(this).removeAttr("disabled")
        }).trigger("change");

        // filesystem
        panel.find("#options_filesystem_type").change(function () {
            if (!$(this).is(":checked"))
                panel.find("#tab-filesystem_settings .toggleable").find("input, select, textarea").not(this).not("input[type='hidden']").attr("disabled", true)
            else
                panel.find("#tab-filesystem_settings .toggleable").find("input, select, textarea").not(this).removeAttr("disabled")
            $(this).removeAttr("disabled");
        }).trigger("change");
    });
</script>
